﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MODEL;

namespace StudentManage
{
    public partial class Frm_Login : Form
    {
        public Frm_Login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Account account = new Account();
            account.UserName = txtLoginName.Text;
            account.Password = txtLoginPwd.Text;

            Class @class = new Class();
            @class.C_No = txtLoginPwd.Text;
            @class.C_Name = txtLoginName.Text;

            StuCard stuCard = new StuCard();
            stuCard.StuId = txtLoginPwd.Text;
            stuCard.StuName = txtLoginName.Text;

            int num = BLL.AccountManage.Login(account);
            int num2 = BLL.ClassManage.ChaXunClassPwd(@class);
            int num3 = BLL.StuCardManage.StuCardService.ChaXunStudentPwd(stuCard);

            //Frm_Account frm_Account = new Frm_Account();

            Frm_Main frm_Main = new Frm_Main();
            if (radioButton1.Checked == true)
            {
                if (num3 > 0)
                {
                    //定义打开窗体的方法

                    //void RunFrm()
                    //{
                    //frm_Main.ShowDialog();
                    //}

                    //frm_Account.lbl_UserName.Text = stuCard.StuName;
                    //frm_Account.lbl_Pwd.Text = "学生";
                    frm_Main.系统设置ToolStripMenuItem.Visible = false;
                    frm_Main.班级管理ToolStripMenuItem.Visible = false;
                    frm_Main.考勤规则ToolStripMenuItem.Visible = false;

                    this.DialogResult = DialogResult.OK;
                    this.Close();

                    //打开登录窗体，退出此窗体

                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                }
            }


            if (radioButton2.Checked == true)
            {
                if (num2 > 0)
                {
                    //frm_Account.lbl_UserName.Text = @class.C_Name;
                    //frm_Account.lbl_Pwd.Text = "班主任";
                    //定义打开窗体的方法
                    //void RunFrm()
                    //{
                    //    new Frm_Main().ShowDialog();
                    //}
                    //打开登录窗体，退出此窗体
                    //Thread th = new Thread(RunFrm);
                    //th.Start();
                    //this.Close();
                    //frm_Main.系统设置ToolStripMenuItem.Visible = false;
                    //frm_Main.班级管理ToolStripMenuItem.Visible = false;
                    frm_Main.考勤规则ToolStripMenuItem.Visible = false;

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                }
            }
            
            if (radioButton3.Checked == true)
            {
                if (num > 0)
                {

                    //定义打开窗体的方法
                    void RunFrm()
                    {
                        new Frm_Main().ShowDialog();
                    }
                    //打开登录窗体，退出此窗体
                    Thread th = new Thread(RunFrm);
                    th.Start();
                    this.Close();

                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                }
            }



        }

        private void Frm_Login_Load(object sender, EventArgs e)
        {

        }
    }
}
